package cn.lovecyy.mockjson.core.funcs;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import cn.lovecyy.mockjson.core.domain.TypeConfig;

/**
 * SubFunc
 *
 * @author Yakir
 */
public class SubFunc implements FuncMock {

	@Override
	public String getFuncName() {
		return "sub";
	}

	@Override
	public Object apply(TypeConfig config, String... args) {
		if (args == null || args.length < 2)
			return args != null && args.length > 0 ? args[0] : null;
		String val = args[0];
		int start = Convert.toInt(args[1]);
		int end = Convert.toInt(args[2]);
		return StrUtil.sub(val, start, end);
	}

}
